package com.tsx.leetcode.hot100.easy;

/**
 * 只出现一次的数字
 * <a href="https://leetcode.cn/problems/single-number">只出现一次的数字</a>
 * <p>
 * 1. 使用异或运算符 ^
 * 2. a ^ a = 0
 * 3. a ^ 0 = a
 */
public class Q136SingleNumber {
    public static void main(String[] args) {
        int[] nums = new int[]{2, 3, 4, 5, 6, 2, 3, 4, 5};
        int res = singleNumber(nums);
        System.out.println("res = " + res);
    }

    public static int singleNumber(int[] nums) {
        int single = 0;
        for (int num : nums) {
            single ^= num;
        }
        return single;
    }
}
